﻿using ConsoleApp1;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        Form2 form2;
        public Form1()
        {
            InitializeComponent();
            
            List<Order> list = Program.orderService1.AllOrder;
            dataGridView1.DataSource = list;
        }
        
        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void groupBox1_Enter_1(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 1)
            {
                Visible = false;
                Program.chosenOrder = Program.orderService1.AllOrder[dataGridView1.SelectedRows[0].Index];
                form2 = new Form2();
                form2.Show();
            }
            
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedIndex)
            {
                case 0:
                    string s = textBox1.Text;
                    dataGridView1.DataSource = Program.orderService1.Search(s);
                    dataGridView1.Refresh();
                    break;
                case 1:
                    dataGridView1.DataSource = Program.orderService1.Search(new Customer(textBox1.Text));
                    dataGridView1.Refresh();
                    break;
                case 2:
                    dataGridView1.DataSource = Program.orderService1.Search(
                        new OrderDetail(new Goods(textBox1.Text, 0), 0));
                    dataGridView1.Refresh();
                    break;
                default:
                    List<Order> list = Program.orderService1.AllOrder;
                    dataGridView1.DataSource = list;
                    break;
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Visible = false;
            button6.Visible = false;
            label1.Text = "客户名:";
            label2.Text = "时间";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.Visible = false;
            button5.Visible = false;
            label2.Text = "ID:";
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            string s = textBox3.Text;
            string[] s1 = s.Split('/', ' ', ':');
            Time t = new Time(int.Parse(s1[0]), int.Parse(s1[1]), int.Parse(s1[2]), int.Parse(s1[3]), int.Parse(s1[4]));
            Program.orderService1.AddOrder(new Customer(textBox2.Text), new List<OrderDetail>(), t);
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = Program.orderService1.AllOrder;
            dataGridView1.Update();
            dataGridView1.Refresh();
            dataGridView1.Visible = true;

            button6.Visible = true;
            textBox2.Text = "";
            textBox3.Text = "";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string s = textBox3.Text;
            Program.orderService1.RemoveOrder(s);
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = Program.orderService1.AllOrder;
            dataGridView1.Refresh();

            dataGridView1.Visible = true;

            button5.Visible = true;
            textBox2.Text = "";
            textBox3.Text = "";
        }
    }
}